package com.yycx.common.base.module.export;

import cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity;
import cn.hutool.core.util.ArrayUtil;
import com.yycx.common.base.utils.FlymeUtils;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.ArrayList;
import java.util.List;

/**
 * 导出字段扩展对象
 *
 * @author zyf
 */
@Data
@EqualsAndHashCode(callSuper = false)
public class ExportField extends ExcelExportEntity {

    /**
     * 实体映射的字段
     */
    private String entityName;

    /**
     * sql-group-by去除字段：0 否 1是
     */
    private Integer groupBy;

    /**
     * 合并单元格
     */
    private List<ExportField> children;

    /**
     * 字典数据
     */
    private List<DictDataVo> dictData;


    /**
     * 设置字典替换值
     */
    public void setReplace() {
        if (FlymeUtils.isNotEmpty(dictData)) {
            List<String> replace = new ArrayList<>();
            for (DictDataVo dictDataVo : dictData) {
                replace.add(dictDataVo.getLabel() + "_" + dictDataVo.getValue());
            }
            this.setReplace(ArrayUtil.toArray(replace, String.class));
        }
    }
}
